1. Field of the Invention
The present invention relates to computer systems. More particularly, the present invention relates interpreter optimization for native endianness.
2. Background
A known problem for software developers and computer users is the lack of portability of software across operating system platforms. As a response to this concern, the Java(trademark) programming language was developed at Sun Microsystems as a platform independent, object oriented computer language.
Java(trademark) achieves its operating system independence by being both a compiled and interpreted language. The way in which this independence is achieved is illustrated in FIG. 1. First, Java(trademark) source code 10, which consists of Java(trademark) classfiles, is compiled into a generic intermediate format called Java(trademark) bytecode 14. Java(trademark)""s bytecodes consist of a sequence of single byte opcodes, each of which identify a particular operation to be carried out. Additionally, some of the opcodes have parameters. For example, opcode number 21, iload less than varnum greater than , takes the single-word integer value stored in the local variable, varnum, and pushes it onto a stack.
Next, the bytecodes 14 are interpreted by a Java(trademark) Virtual Machine (JVM) 16. The JVM executes the bytecodes, either by interpreting them or by compiling them to native machine code and then executing the compiled code. The JVM 16 is a stacked-based implementation of a xe2x80x9cvirtualxe2x80x9d processor that shares many characteristics with physical microprocessors. The bytecodes 14 executed by the JVM 16 are essentially a machine instruction set, and as will be appreciated by those of ordinary skill in the art, are similar to the assembly language of a computing machine. Accordingly, every hardware platform or operating system may have a unique implementation of the JVM 16, called a Java(trademark) Runtime System, to route the universal bytecode calls to the underlying native system 18.
Although Java(trademark) provides portability through bytecodes, Java(trademark) programs lag natively compiled programs, written in languages like C/C++, in their execution time. When a user activates a Java program on a Web Page, the user must wait not only for the program to download but also to be interpreted. To improve Java""s execution time, optimizations can be introduced into the processing of Java(trademark) bytecodes 14. These optimizations can be implemented in a variety of manners including as Stand-Alone Optimizers (SAOs) or as part of Just-in-Time (JIT) compilers.
A SAO transforms an input classfile containing bytecode 14 into an output classfile containing bytecodes that more efficiently perform the same operations. A JIT transforms an input classfile containing bytecode 14 into an executable program. Prior to the development of JITs, a JVM 16 would step through all the bytecode instructions in a program and mechanically perform the native code calls. With a JIT compiler, however, the JVM 16 first makes a call to the JIT which compiles the instructions into native code that is then run directly on the native operating system 18. The JIT compiler permits natively complied code to run faster and makes it so that the code only needs to be compiled once. Further, JIT compilers offer a stage at which the executable code can be optimized.
Optimizing the processing of Java(trademark) bytecodes is complicated by the way in which different computers store data. The xe2x80x9cendiannessxe2x80x9d of a computer CPU is determined by whether the least significant bit is in the lowest or highest addressed byte. In a little-endian computer, the low-order byte of a number is stored in memory at the lowest address, and the high-order byte at the highest address. In a big-endian computer, the high-order byte of a number is stored in memory at the lowest address, and the low-order byte at the highest address. Big-endian order is also known as network order. Table 1 illustrates the different byte ordering used by little-endian and big-endian computers.
The different byte ordering means that little-endian and big-endian systems store multibyte quantities differently. For example, the 32-bit (four byte) quantity represented by the hex constant 0xc3x9711AABBCC is equivalent to the number 296,401,868. However, Table 2 shows the different ways little-endian and big-endian systems store the value 0xc3x9711AABBCC. The most significant (big) byte, 0xc3x9711, is stored first on the big-endian system and last on the little-endian system.
Intel processors and DEC Alphas use little-endian byte order. IBM""s 370 computers, most RISC-based computers and Motorola microprocessors use big-endian byte order.
Native and translated programs cannot share binary data without taking into account the big-endian vs. little-endian architectural differences. Otherwise, the same binary data residing on disk or in memory looks different to each type of program. Little-endian systems typically order bytes right to left, so the native program looks to the last byte for the most significant bit. Because a typical big-endian system orders bytes in the reverse direction, the translated program looks to the first byte for the most significant bit. For example, if a big-endian processor writes a file targeted to a little-endian processor, the byte order must be reversed. Similarly, if a little-endian processor reads a file that was targeted for a big-endian processor, the byte order must be reversed before the contents of the file are interpreted.
Furthermore, files containing varying length fields cannot be converted from one byte-ordering convention to another simply by swapping all the bytes. Some examples of files having varying length fields include program binary files and Java(trademark) classfiles. To change byte ordering, programs are typically recompiled using the appropriate compiler option. However, Java(trademark) classfiles must be in big-endian order. In this case, a Java(trademark) interpreter running on a little-endian processor typically organizes code according to native endianness on the fly.
Increasing demands on computers in general create an incentive to optimize the speed and efficiency of program execution. The run time nature of Java(trademark)-like systems provides a significant additional incentive for such optimizations. Accordingly, a need exists in the prior art for a method for optimizing program execution.
A method for interpreter optimization includes receiving multiple data units organized according to a first endian order, reordering the data units according to a second endian order and interpreting the reordered data units. According to one aspect, the data units include at least one opcode having at least one operand, each operand including at least one data unit. According to another aspect, a class loader reorders the code within a classfile from big-endian format to little-endian format.